import React, { useEffect, useState } from 'react';
import {
    Button,
    Cascader,
    DatePicker,
    Form,
    Input,
    InputNumber,
    Radio,
    Select,
    Switch,
    TreeSelect,
} from 'antd';
import dayjs from 'dayjs';
import { useDispatch } from 'react-redux';
import * as asyncfn from '../store/ctmSlice'
const Myfrom = (props) => {
    let dispatch = useDispatch()
    const [form] = Form.useForm();
    useEffect(() => {
        if (props.itemobj) {
            let times = {
                ...props.itemobj,
                time: props.itemobj.time ? dayjs(props.itemobj.time) : undefined
            }
            form.setFieldsValue(times)
        }
    })
    const onFinish = values => {
        console.log('Success:', values);
        if (props.title == "新增") {
            let obj = {
                ...values,
                "id": new Date().getTime()
            }
            dispatch(asyncfn.async_getaddshoplist(obj))
        } else {
            let obj = {
                ...values,
                "id": props.itemobj.id
            }
            dispatch(asyncfn.async_geteaitshoplist(obj))
        }
        props.handleCancel()
    };
    return (
        <Form
            form={form}
            onFinish={onFinish}
            labelCol={{ span: 4 }}
            wrapperCol={{ span: 14 }}
            layout="horizontal"
            style={{ maxWidth: 600 }}
        >
            <Form.Item label="优惠劵名称" name="title">
                <Input />
            </Form.Item>
            <Form.Item label="领取时间" name="time">
                <DatePicker />
            </Form.Item>
            <Form.Item label="发布数量" name="num">
                <InputNumber />
            </Form.Item>
            <Form.Item label="状态" name="Collect">
                <Radio.Group
                    options={[
                        { value: true, label: '开启' },
                        { value: false, label: '关闭' },
                    ]}
                />
            </Form.Item>
            <Form.Item>
                <Button type='primary' htmlType='submit'>确认</Button>
            </Form.Item>
        </Form>
    );
};
export default Myfrom;